import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import ManageView from '../views/ManageView.vue'
import UserQuery from '../components/UserQuery.vue'
import UserAdd from '../components/UserAdd.vue'
import UserEdit from '../components/UserEdit.vue'
import OrdersQuery from '../components/OrdersQuery.vue'
import ShoppingCart from '../components/ShoppingCart.vue'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'ManageView',
    component: ManageView,
    children: [
      {
        path: '/userquery',
        name: 'UserQuery',
        component: UserQuery
      },
      {
        path: '/useradd',
        name: 'UserAdd',
        component: UserAdd
      },
      {
        path: '/useredit/:id/:userName/:userPwd/:gender/:roleId',
        name: 'UserEdit',
        component: UserEdit,
        props: (route) => ({
          id: route.params.id,
          userName: route.params.userName,
          userPwd: route.params.userPwd,
          gender: route.params.gender,
          roleId: route.params.roleId
        })
      },
      {
        path: '/ordersquery',
        name: 'OrdersQuery',
        component: OrdersQuery
      },
      {
        path: '/shoppingcart',
        name: 'ShoppingCart',
        component: ShoppingCart
      },
    ]
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

export default router
